package cn.wolfcode.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class Appointment {

    public static final int STATUS_TYPE_APPOINT = 0;  //预约中、预约中(待确认)
    public static final int STATUS_TYPE_PERFORM = 1;  //履行中
    public static final int STATUS_TYPE_CONSUME = 2;  //消费中
    public static final int STATUS_TYPE_PLACEBO = 3;  //归档中
    public static final int STATUS_TYPE_ABANDON = 4;  //废弃

    /** 主键 */
    private Long id;

    /** 预约单流水号 */
    private String ano;

    /** 预约单状态 （预约中/履行中/消费中/归档/废弃单）*/
    private Integer status = STATUS_TYPE_APPOINT;

    /** 业务大类 */
    //private Long categoryId;
    private SystemDictionary category;

    /** 预约说明 */
    private String info;

    /** 联系电话 */
    private String contactTel;

    /** 联系人名称 */
    private String contactName;

    /** 预约门店 */
    //private Long businessId;
    private Business business;

    /** 创建时间 */
    private Date createTime;

    /** 预约时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @JSONField(format = "yyyy-MM-dd HH:mm")  //在JSON.toJSONString(this);时候有效
    private Date appointmentTime;


    public String toJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("status", status);
        map.put("categoryId", category.getId());
        map.put("categoryParentId", category.getParentId());
        map.put("info", info);
        map.put("contactTel", contactTel);
        map.put("contactName", contactName);
        map.put("appointmentTime", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(appointmentTime));
        map.put("businessId", business.getId());

        return JSON.toJSONString(map);
    }

    public String getStatusDisplay(){
        switch (status){
            case STATUS_TYPE_APPOINT : return "待确认";
            case STATUS_TYPE_PERFORM : return "履行中";
            case STATUS_TYPE_CONSUME : return "消费中";
            case STATUS_TYPE_PLACEBO: return "归档中";
            case STATUS_TYPE_ABANDON : return "废弃";
            default: return "异常状态";
        }
    }
}